<?php
/********************************* Social Widget **************************************/
class Social_Widget extends WP_Widget{
    
    public function Social_Widget(){
        $widget_ops = array('description'=>'Social Link');
		$control_ops = array('width' => 400, 'height' => 300);
        parent::WP_Widget(false,$name='Social Link',$widget_ops,$control_ops);
    }
    
    /* Create widget form */
    public function form($instance){
        //Defaults
        $instance = wp_parse_args( (array) $instance, array('linkfacebook'=>'', 'linktwitter'=>'', 'skype'=>'') );
 
        $linkfacebook = htmlspecialchars($instance['linkfacebook']);
        $linktwitter = htmlspecialchars($instance['linktwitter']);        
        $skype = htmlspecialchars($instance['skype']);
        # linkfacebook
        echo '<p><label for="' . $this->get_field_id('linkfacebook') . '">' . 'Link Facebook:' . '</label><input class="widefat" id="' . $this->get_field_id('linkfacebook') . '" name="' . $this->get_field_name('linkfacebook') . '" type="text" value="' . $linkfacebook . '" /></p>';
        # linktwitter
        echo '<p><label for="' . $this->get_field_id('linktwitter') . '">' . 'Link Twitter:' . '</label><input class="widefat" id="' . $this->get_field_id('linktwitter') . '" name="' . $this->get_field_name('linktwitter') . '" type="text" value="' . $linktwitter . '" /></p>';
        # skype
        echo '<p><label for="' . $this->get_field_id('skype') . '">' . 'Skype:' . '</label><input class="widefat" id="' . $this->get_field_id('skype') . '" name="' . $this->get_field_name('skype') . '" type="text" value="' . $skype . '" /></p>';
    }
    
    /* Update widget */
    public function update($new_instance, $old_instance){
        $instance = $old_instance;
        $instance['linkfacebook'] = stripslashes($new_instance['linkfacebook']);
        $instance['linktwitter'] = stripslashes($new_instance['linktwitter']);
        $instance['skype'] = stripslashes($new_instance['skype']);
		
        return $instance;
    }
    
     /* Displays the Widget in the front-end */
    public function widget($args, $instance){
        extract($args);
        
        $linkfacebook = empty($instance['linkfacebook']) ? '' : $instance['linkfacebook'];
        $linktwitter = empty($instance['linktwitter']) ? '' : $instance['linktwitter'];
        $skype = empty($instance['skype']) ? '' : $instance['skype'];
        ?>
            <li><a href="<?php echo ($linkfacebook!='')? $linkfacebook : '#'; ?>" target="_blank"><img src="<?php bloginfo('template_url'); ?>/images/ico-fb.png" alt="facebook" /></a></li>
            <li><a href="<?php echo ($linktwitter!='') ? $linktwitter : '#'; ?>" target="_blank"><img src="<?php bloginfo('template_url'); ?>/images/ico-twitter.png" alt="twitter" /></a></li>
            <li>
                <script type="text/javascript" src="http://download.skype.com/share/skypebuttons/js/skypeCheck.js"></script>
                <a href="skype:<?php echo ($skype!='') ? $skype : '#'; ?>?call" target="_blank"><img src="<?php bloginfo('template_url'); ?>/images/ico-call-me.png" alt="call-me" /></a>
            </li>
        <?php
    }
}

add_action( 'widgets_init', create_function( '', 'register_widget( "Social_Widget" );' ) );
?>

